package hung.vnptthanhhoa.cookingbook;

import hung.vnptthanhhoa.adapter.CookingList;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ArrayAdapter_Cooking extends ArrayAdapter<CookingList> {

	private Activity context;
	private ArrayList<CookingList> arrayList;

	public ArrayAdapter_Cooking(Activity context,
			ArrayList<CookingList> arrayList) {
		super(context, R.layout.item_listview_cooking);
		this.context = context;
		this.arrayList = arrayList;
	}

	public View getView(int position, View view, ViewGroup parent) {
		LayoutInflater inflater = context.getLayoutInflater();
		View rowView = inflater.inflate(R.layout.item_listview_cooking, null,
				true);
		TextView txtTitle = (TextView) rowView
				.findViewById(R.id.item_listview_cooking_text);
		ImageView imageView = (ImageView) rowView
				.findViewById(R.id.item_listview_cooking_img);

		CookingList cookingList = arrayList.get(position);
		txtTitle.setText(cookingList.getName());

		Context context1 = imageView.getContext();
		int idImage = context1.getResources().getIdentifier(
				cookingList.getImage(), "drawable", context1.getPackageName());
		imageView.setImageResource(idImage);
		TextView txtNote = (TextView) rowView
				.findViewById(R.id.item_listview_cooking_note);
		txtNote.setText("Có " + cookingList.getCount() + " món ăn.");
		return rowView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public CookingList getItem(int position) {
		return arrayList.get(position);
	}

}
